package com.xbai.framework.exception;

import com.xbai.entity.Result;
import com.xbai.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author jxbai
 * @desc 全局异常处理类
 * @date 2021/1/27
 */
@ControllerAdvice
public class BaseExceptionHandler {

    /**
     * 异常处理
     * @param e {@link Exception}
     * @return {@link Result}
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }
}
